Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

$solutionName = "EFSBWFActivities.getListIDByListTitleSB.wsp"
$SiteCollectionUrl = "http://hvsp2010a/sites/CallCentre"

$sol = Get-SPUserSolution -Site $SiteCollectionUrl | Where-Object {$_.Name -eq $solutionName}
if ($sol -ne $null) {
	if($sol.Status -eq "Activated")
	{	
		UnInstall-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl -Confirm:$false
		write-host "uninstalling $($solutionName) ..." -NoNewline
		do 
		{
			Write-Host "." -NoNewline
			Start-Sleep 1
		}
		while ((Get-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl).JobExists -eq $true)
		Write-Host "ok"
	}
	else
	{
		Write-Host "Solution $($solutionName) not deployed"
	}
	
	$sol = Get-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl
	if($sol.Status -eq "Activated")
	{
		$sol2 = Get-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl
		Write-Host "test"
	}
	else
	{
		write-host "removing $($solutionName) ..."
		Remove-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl -Confirm:$false
	}
}
else
{
	Write-Host "Solution $($solutionName) not installed"
}

Write-Host "Completed.  Any key to exit..."
#Read-Host
